<template>
    <div class="modelBox">
        <div class="modelTitle">设计灵感库 海量素材</div>
        <div class="modelContent">13万+海量模型库，持续更新</div>
        <div class="materType">
            <div class="materTypeTitle" v-for="(item, index) in materList" :key="index" :class="activeType == index ? 'activeTitle' : 'materTypeTitle'" @click="chooseType(item, index)">
                <div class="materTypeImg">
                    {{ item.name }}

                    <img :src="getImg(item.imgActive)" alt="" v-if="activeType == index" />
                    <img :src="getImg(item.imgUrl)" alt="" v-else />
                </div>
                <div class="triangle" v-if="activeType == index"></div>
            </div>
        </div>
        <scroll :items="items" direction="left" :speed="30" height="160px" width="100%" style="margin: auto">
            <template #default="{ items, phase }">
                <div style="display: flex">
                    <div v-for="item in items" :key="`${phase}-${item.id}`" class="horizontal-item">
                        {{ item.text }}
                    </div>
                </div>
            </template>
        </scroll>
        <scroll :items="items" direction="left" :speed="55" height="160px" width="100%" style="margin: auto; margin-top: 30px">
            <template #default="{ items, phase }">
                <div style="display: flex">
                    <div v-for="item in items" :key="`${phase}-${item.id}`" class="horizontal-item">
                        {{ item.text }}
                    </div>
                </div>
            </template>
        </scroll>
    </div>
</template>

<script setup>
import scroll from "../../components/scroll.vue";
const activeType = ref(0);
const svgModules = import.meta.glob("~/assets/svg/active/*.svg", { eager: true });

const getImg = (cardContent) => {
    const key = `/assets/svg/active/${cardContent}.svg`;
    return svgModules[key]?.default || "/fallback.svg";
};
const items = [
    { id: 1, text: "内容块 1" },
    { id: 2, text: "内容块 2" },
    { id: 2, text: "内容块 3" },
    { id: 2, text: "内容块 4" },
    { id: 2, text: "内容块 5" },
    { id: 2, text: "内容块 6" },
    { id: 2, text: "内容块 7" },
    { id: 2, text: "内容块 8" },
    // ...
];

const materList = ref([
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
    {
        name: "家具模型",
        imgUrl: "tubusi_w_index_tab1_yz_n",
        imgActive: "tubusi_w_index_tab1_zw_y",
    },
]);
const chooseType = (item, index) => {
    activeType.value = index;
};
</script>

<style lang="less" scoped>
.horizontal-item {
    width: 160px;
    height: 160px;
    background: var(--writLightSix);
    border-radius: 24px;
    border: 1px solid var(--bjHomeWhite);
    margin: 0 10px;
    color: var(--white);
    text-align: center;
    cursor: pointer;
}
.loadingBox {
    width: 100px;
    height: 100%;
    background-color: red;
    position: absolute;
}
.modelBox {
    background: var(--bjHomeWhite);
    padding-bottom: 140px;
    .materType {
        display: flex;
        justify-content: center;
        margin-top: 60px;
        margin-bottom: 46px;
        .materTypeTitle {
            height: 60px;
            background: var(--white);
            box-shadow: 0px 0px 20px 0px var(--shadow);
            border-radius: 8px;
            margin: 0 10px;
            padding: 0 20px;
            position: relative;
            cursor: pointer;
            .materTypeImg {
                height: 24px;
                margin-top: 18px;
                line-height: 24px;
                font-weight: 500;
                font-size: 16px;
                color: var(--black);
                line-height: 24px;
                display: flex;

                img {
                    width: 24px;
                    height: 24px;
                    margin-left: 20px;
                }
            }
            .triangle {
                width: 16px;
                height: 16px;
                background: var(--black);
                position: absolute;
                left: 50%;
                transform: translateX(-50%) translateY(50%) rotate(45deg);
            }
        }
        .activeTitle {
            height: 60px;
            background: var(--white);
            box-shadow: 0px 0px 20px 0px var(--shadow);
            border-radius: 8px;
            margin: 0 10px;
            padding: 0 20px;
            position: relative;
            background: var(--black);
            .materTypeImg {
                height: 24px;
                margin-top: 18px;
                line-height: 24px;
                font-weight: 500;
                font-size: 16px;
                color: var(--white);
                line-height: 24px;
                display: flex;

                img {
                    width: 24px;
                    height: 24px;
                    margin-left: 20px;
                }
            }
            .triangle {
                width: 16px;
                height: 16px;
                background: var(--black);
                position: absolute;
                left: 50%;
                transform: translateX(-50%) translateY(50%) rotate(45deg);
            }
        }
    }
}
.modelImg {
    width: 100%;
    height: 60px;
    background: var(--black);
    border-radius: 8px;
    color: var(--white);
    font-weight: 500;
    font-size: 20px;
    line-height: 60px;
    text-align: center;
}

.modelTitle {
    font-weight: 600;
    font-size: 40px;
    color: var(--black);
    line-height: 56px;
    width: 100%;
    padding-top: 140px;
    box-sizing: border-box;
    text-align: center;
}
.modelContent {
    width: 100%;
    font-weight: 400;
    font-size: 20px;
    color: var(--black);
    line-height: 28px;
    text-align: center;
    margin-top: 16px;
}
</style>
